package org.example.线程.中断;

/**
 * @author mumucgq
 * @create 2020-07-24 9:37
 */
public  class InterruptTest implements Runnable {

    @Override
    public void run() {

        try {
            System.out.println();
            System.out.println(Thread.currentThread().isInterrupted());//输出false
            Thread.currentThread().interrupt(); //当前线程中断
            System.out.println(Thread.currentThread().isInterrupted());//输出true
            Thread.sleep(3000);//中断后执行sleep会抛出异常
        } catch (InterruptedException e) {
            e.printStackTrace();
            System.out.println(Thread.currentThread().isInterrupted());//输出false

        }

    }

    public static void main(String[] args) {
        Thread t= new Thread(new InterruptTest());
        t.start();

    }
}
